package com.chebaohui.iqs.service.impl.deal.taiping.ev;
import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.service.impl.deal.taiping.DirectTp;
import com.chebaohui.iqs.service.impl.deal.taiping.PublicNew;
import com.chebaohui.iqs.service.impl.deal.taiping.RequestHead;
import com.chebaohui.iqs.service.impl.deal.taiping.ResTaiPing;

/**
 * E02--该接口是根据车牌号判断是否可以直接报价
 * 
 * @author xielonghai
 * @version 2016-07-01
 */
public class E02Request {

	/**
	 * 根据车牌查询车辆是否可以直接报价
	 * 
	 * @param licenseNo
	 *            车牌号
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @return
	 */
	public static ResTaiPing requestE02(String session, String licenseNo) {
		String value = CompanyValue.TAIPING + ":辅助接口-根据车牌号:" + licenseNo + ",判断是否可以直接报价";
		String[] key = { "baseInfo" };
		return DirectTp.request(value, PublicNew.REQUEST_URL + "/judgeQuotetion", getRequest(session, licenseNo),
				key);
	}

	/**
	 * 获取--E02-车辆是否可以直接报价------请求参数
	 * 
	 * @param licenseNo
	 *            车牌号
	 * @return
	 */
	private static String getRequest(String session, String licenseNo) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<vehicle>";
		request = request + "\n\t\t" + "<licenseNo>" + licenseNo + "</licenseNo>";
		request = request + "\n\t" + "</vehicle>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
